﻿namespace Shared.Http.APIResult
{
    /// <summary>
    /// 静态工厂方法
    /// </summary>
    public static class ApiResult
    {
        /// <summary>
        /// 创建成功响应
        /// </summary>
        public static ApiResult<T> Success<T>(
            T data,
            Guid traceId) =>
            new()
            {
                Code = ApiStatusCode.Success,
                Data = data,
                TraceId = traceId
            };

        /// <summary>
        /// 创建失败响应
        /// </summary>
        public static ApiResult<object?> Fail(
            ApiStatusCode code,
            Guid traceId,
            IList<ErrorData> errors) =>
            new()
            {
                Code = code,
                Errors = errors,
                TraceId = traceId
            };
        public static ApiResult<T> Fail<T>(
            ApiStatusCode code,
            Guid traceId,
            IList<ErrorData> errors) =>
            new()
            {
                Code = code,
                Errors = errors,
                TraceId = traceId,
            };

        public static ApiResult<T> PartFail<T>(
            T data,
            Guid traceId,
            IList<ErrorData> errors) =>
            new()
            {
                Code = ApiStatusCode.PartialFailure,
                Data = data,
                Errors = errors,
                TraceId = traceId
            };
    }
}
